#include "AnimatedDrawable.h"
#include <graphic/DrawManager.h>
#include <main/Globals.h>
#include <main/mainconstants.h>


AnimatedDrawable::AnimatedDrawable(const std::string& atlas, Entity* entity, int w, int h) :
	Drawable(atlas, entity, &w, &h), animation(texture, w, h), currentTime(0.f), animationSpeed(0) {
}

void AnimatedDrawable::update() {
	Drawable::update();

    if (animation.isPlaying() == false && animation.destroyable()) {
        Globals::gDrawManager->removeDrawable(this);
    }

	if(animationSpeed == 0) {
		return;
	}
	currentTime += MS_PER_FRAME_FLOAT;
	if(currentTime >= animationSpeed){
		currentTime = 0.f;
		animation.update();
	}
}


void AnimatedDrawable::moveAnimation() {
	animation.update();
}